# Contributor: Michael Pirogov <vbnet.ru@gmail.com>
# Maintainer: Michael Pirogov <vbnet.ru@gmail.com>
pkgname=odyssey
pkgver=1.1
pkgrel=1
pkgdesc="Scalable PostgreSQL connection pooler"
url="https://github.com/yandex/odyssey"
arch="x86_64 x86" # limited by machinarium supported architecture
license="BSD-3-Clause"
makedepends="cmake postgresql-dev openssl-dev linux-pam-dev"
options="!check" # https://github.com/yandex/odyssey/issues/134
subpackages="$pkgname-openrc"
source="$pkgname-$pkgver-$pkgrel.tar.gz::https://github.com/yandex/odyssey/archive/$pkgver.tar.gz
	odyssey.initd
	odyssey.confd"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build \
		-DPOSTGRESQL_INCLUDE_DIR="$(pg_config --includedir)/server" \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_C_FLAGS="$CFLAGS" \
		$CMAKE_CROSSOPTS .
	make -C build
}

check() {
	cd "$builddir"/build/test
	./odyssey_test
}

package() {
	install -Dm755 "$builddir"/build/sources/$pkgname \
		"$pkgdir"/usr/bin/$pkgname
	install -Dm600 "$builddir"/$pkgname.conf \
		"$pkgdir"/etc/$pkgname.conf.example
	install -Dm755 "$srcdir"/$pkgname.initd \
		"$pkgdir"/etc/init.d/$pkgname
	install -Dm644 "$srcdir"/$pkgname.confd \
		"$pkgdir"/etc/conf.d/$pkgname

}

sha512sums="640eb0c68c274ad2b58edf854ae969e47b83376303c39a61cb8752598feb1afe612e62e41a373fa2630dea2f2b1682b2427058501b2db1b4f5b5eb1d9cc03090  odyssey-1.1-1.tar.gz
a1f129b06476c103465e9e649e88e1d5da071a377453e7a5b6dce4734928e8a5eb1c29b4a026d38b81587e6ca813ac3f533c668a264ae4ae7997716c2ec85715  odyssey.initd
1e9fdd3cc7cf0d789b2ea57b275cca6de171d3adc887f1cddfb5a0b273988a514db133e58403fd5a01ec0511446b8746c6a78137df1d5141c7499065e9bd745a  odyssey.confd"
